<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>资讯添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="/static/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
    <style type="text/css">
        .uploadImg {
            border: none;
            width: 150px;
            display: block;
            margin-top: 10px;
        }
    </style>
</head>
<body>

<form class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="art_title" value="" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属机构</label>
        <div class="layui-input-block">
            <select name="art_institution_id">
                {volist name="institutionData" id="vo" key="index"}
                <option value="{$vo['ins_id']}">{$vo['ins_name']}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章作者</label>
        <div class="layui-input-block">
            <input type="text" name="art_author" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input id="" type="number" name="art_sort" value="" placeholder="请输入整数，默认序号为50，序号越小排序越靠前"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">一级分类</label>
        <div class="layui-input-block">
            <select name="parentCategory" lay-filter="parentCategory" id="parentCategory">
                <option value="{$parentCategoryInfo['acc_id']}">{$parentCategoryInfo['acc_name']}</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">二级分类</label>
        <div class="layui-input-block">
            <select name="childCategory" lay-filter="childCategory" id="childCategory">
                <option value="-1" selected>请选择分类</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">来源</label>
        <div class="layui-input-block">
            <input type="text" name="art_source" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">关键字</label>
        <div class="layui-input-block">
            <input type="text" name="art_keywords" value="" class="layui-input" placeholder="关键字之间使用逗号分隔">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="upload">上传图片</button>
                <img id="demo1" class="uploadImg">
                <input type="hidden" name="art_thumb" id="art_thumb">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">跳转地址</label>
        <div class="layui-input-block">
            <input type="text" name="art_url" value="" class="layui-input">
        </div>
    </div>

    {if $isGoodClass}
    <div class="layui-form-item">
        <label class="layui-form-label">购买连接</label>
        <div class="layui-input-block">
            <input type="text" name="art_buy_url" value="" class="layui-input">
        </div>
    </div>
    {/if}

    <div class="layui-form-item">
        <label class="layui-form-label">过期时间</label>
        <div class="layui-input-block">
            <input type="text" name="art_expire_time" id="date"  placeholder="超过该时间，将不再显示本文章；不填表示永不过期" autocomplete="off" class="layui-input">
        </div>
    </div>
    {if !$isInstitutionAdmin}
    <div class="layui-form-item">
        <label class="layui-form-label">是否置顶</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="art_istop" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否热门</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="art_ishot" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="art_isshow" lay-skin="switch" lay-text="是|否" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否审核</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="art_ischeck" lay-skin="switch" lay-text="已审核|未审核" >
        </div>
    </div>
    {/if}
    <div class="layui-form-item">
        <label class="layui-form-label">摘要</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入文章摘要" class="layui-textarea" name="art_description"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block" style="z-index: 1;">
                                    <textarea name="art_content" id="about" cols="30"
                                              rows="10"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="LAY-task-add-submit" id="LAY-task-add-submit">提交</button>
    </div>

</form>
<script src="/static/layuiadmin/lib/jquery.min.js"></script>
<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
    var ue = UE.getEditor("about", {initialFrameHeight: 300, initialFrameWidth: 843.2}); //富文本编辑器对象
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', "upload","laydate"], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload
            ,laydate=layui.laydate;
        var uploadInst = upload.render({
            elem: '#upload'
            , url: "{:url('admin/article/uploadImg')}"
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var src = res.data.src;
                $("#art_thumb").val(src);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        form.on('select(parentCategory)', function (data) {
            //    {elem: select#parentCategory, value: "3", othis: n.fn.init(1)}
            const value=data.value;
            setChildCategoryInfo(value);
            renderForm();
        })
        laydate.render({
            elem: '#date'
        });


    });

    //页面初始化时触发二级联动效果
    setChildCategoryInfo({$parentCategoryInfo['acc_id']});

    function setChildCategoryInfo(parent_id){
        $("#childCategory").empty();
        $.ajax({
            url: "{:url ('admin/article/getChildCategoryInfo')}",
            type: "post",
            data: {
                parent_id:parent_id
            },
            dataType: "json",
            success: function (res) {
                if(res.msg!=="noData"){
                    $("#childCategory").append(res.data);
                    renderForm();
                }
            }
        })
    }

    function renderForm(){
        layui.use('form', function(){
            var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }


</script>
</body>
</html>
